﻿using B.S.Packaged.Domain;
using B.S.Packaged.ErrorCode;
using B.S.Packaged.WebAPI.Read.Application.Command.PackagingPlanCommands;
using MediatR;
using SqlSugar;

namespace B.S.Packaged.WebAPI.Read.Application.CommandHander.PackagingPlanCommandHandlers
{
    public class GetBYIdPackagingPlanCommandHandler : IRequestHandler<GetBYIdPackagingPlanCommands, APIResult<List<PackagingPlan>>>
    {
        private readonly ISqlSugarClient db;

        public GetBYIdPackagingPlanCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<APIResult<List<PackagingPlan>>> Handle(GetBYIdPackagingPlanCommands request, CancellationToken cancellationToken)
        {
            APIResult<List<PackagingPlan>> result = new APIResult<List<PackagingPlan>>();
            result.code = APIResultCode.success;
            result.msg = "查询成功";

            var list = await db.Queryable<PackagingPlan>().Where(p => p.PackagingPlanId == request.PackagingPlanId).ToListAsync();

            result.data = list;
            return await Task.FromResult(result);
        }
    }
}
